SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].gspPhoto_SEARCH
(
@photoId int = null,
@productId int = null,
@fileName nvarchar(128) = null,
@mimeType nvarchar(128) = null,
@fileSize int = null,
@description nvarchar(256) = null,
@createdDate datetime = null,
@lastModifiedDate datetime = null,
@isDeleted bit = null
)
AS

SELECT
  *
FROM
  [dbo].[Photo]
WHERE
  (@photoId IS NULL OR [PhotoId] = @photoId)
AND
  (@productId IS NULL OR [ProductId] = @productId)
AND
  (@fileName IS NULL OR @fileName = '' OR [FileName] LIKE @fileName + '%')
AND
  (@mimeType IS NULL OR @mimeType = '' OR [MimeType] LIKE @mimeType + '%')
AND
  (@fileSize IS NULL OR [FileSize] = @fileSize)
AND
  (@description IS NULL OR @description = '' OR [Description] LIKE @description + '%')
AND
  (@createdDate IS NULL OR [CreatedDate] = @createdDate)
AND
  (@lastModifiedDate IS NULL OR [LastModifiedDate] = @lastModifiedDate)
AND
  (@isDeleted IS NULL OR [IsDeleted] = @isDeleted)


GO
